package com.rd.student.dashuju.zhengchengxiang.July13th.Test;


import java.util.*;

public class GetListUtils {


    //根据班级查询成员列表
    //返回当前所有班级和班级专业的人数
    //"2班" 2人 "3班" 3人 ...
    //用户可以输入班级
    //"2班" 名字-班级-专业
    public static HashMap getClassInfo(LinkedList list) {

        HashMap hashMap = new HashMap();
        for (int i = 0; i < list.size(); i++) {
            Student student = (Student) list.get(i);
            int key = student.getClasses();

            if (!hashMap.containsKey(key)) {
                hashMap.put(key, 1);
            } else {
                int value = (int) hashMap.get(key);
                hashMap.put(key, value + 1);
            }
        }

        info(hashMap);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入班级：（例如 2）");
        int classes = sc.nextInt();

        System.out.println(classes);
        if (hashMap.containsKey(classes)) {
            for (int i = 0; i < list.size(); i++) {
                Student student = (Student) list.get(i);
                if (student.getClasses()==classes) {
                    System.out.println(student.getName() + "-" + student.getClasses() + "-" + student.getMajor());
                }
            }
        } else {
            System.out.println("没有该班级");
        }
        return hashMap;
    }

    public static void info(HashMap hashMap) {
        Set set = hashMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = hashMap.get(key);
            System.out.println(key + "班： " + value + "人");
        }
    }

}